﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NConf.Interfaces;
using System.Collections.Specialized;
using System.Configuration;

namespace NConf.ConfigSources
{
    /// <summary>
    /// A configuration source populated by the app.config file for the running application.
    /// </summary>
    class AppConfigSource : DictConfigSource
    {
        //---------------------------------------------------------------------

        #region Internal Members

        /// <summary>
        /// The application settings, loaded from the app.config file.
        /// </summary>
        private NameValueCollection appSettings = ConfigurationManager.AppSettings;

        #endregion

        //---------------------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Default Constructor.
        /// </summary>
        public AppConfigSource()
        {
            Configuration = new Dictionary<string, object>();

            // Cache config information
            foreach (string key in appSettings.AllKeys)
            {
                Configuration[key] = appSettings[key];
            } // end foreach
        } // end AppConfigSource

        #endregion

        //---------------------------------------------------------------------
    } // end AppConfigSource
} // end NConf.ConfigSources namespace
